﻿#include "Player.h"
#include "Memory.h"
#include "GlobalVars.h"
#include <iostream>

using namespace std;

Player::Player(uintptr_t addres)
{
	base = addres;
}

Player::~Player()
{

}

void Player::update()
{
	// 区分Actor类型 150 3-自己 1-敌人 0-模型。50 1-人物 0-模型。
	int flag1 = Memory::get().read<int>(base + GlobalVars::get().ofs.playerFlag1_offset);
	int flag2 = Memory::get().read<int>(base + GlobalVars::get().ofs.playerFlag2_offset);
	if (flag1 == 3 && flag2 == 1)
	{
		type = PlayerType::oneself;
	}
	else if (flag1 == 1 && flag2 == 1)
	{
		type = PlayerType::enemy;
	}

	if (type != PlayerType::none)
	{
		// HP
		hp = Memory::get().read<float>(base + GlobalVars::get().ofs.playerHp_offset);
		if (hp > 0)
		{
			// 坐标
			uintptr_t playerOriginAddr = Memory::get().read<uintptr_t>(base + GlobalVars::get().ofs.playerOrigin_offset);
			origin.x = Memory::get().read<float>(playerOriginAddr + GlobalVars::get().ofs.playerOriginX_offset);
			origin.y = Memory::get().read<float>(playerOriginAddr + GlobalVars::get().ofs.playerOriginY_offset);
			origin.z = Memory::get().read<float>(playerOriginAddr + GlobalVars::get().ofs.playerOriginZ_offset);

			// 骨骼
			uintptr_t meshAddr = Memory::get().read<uintptr_t>(base + GlobalVars::get().ofs.playerMesh_offset);
			skeletonArrayAddr = Memory::get().read<uintptr_t>(meshAddr + GlobalVars::get().ofs.playerSkeletonArray_offset);
			skeletonMatrixAddr = meshAddr + GlobalVars::get().ofs.playerSkeletonMatrix_offset;
		}

	}
}
